package com.zx.kitchen.index.common.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.CateListBean;
import com.zx.kitchen.index.common.fragment.CateListFragment;
import com.zx.kitchen.index.common.fragment.GoodReportCateListFragment;
import com.zx.kitchen.index.common.fragment.GoodReportDishListFragment;
import com.zx.kitchen.index.common.utils.TimeUtil;


/**
 * Created by Administrator on 2017/3/20.
 */

public class GoodsReportActivity extends FragmentActivity implements View.OnClickListener {

    private ImageView toolbarLeft;
    private TextView toolbarTitle;
    private TextView tabBusiness;
    private TextView tabPurchase;
    private EditText etStartTime;
    private EditText etEndTime;

    private GoodReportCateListFragment goodReportCateListFragment;
    private GoodReportDishListFragment goodReportDishListFragment;

    public boolean isPurchase = false;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_report);
        initView();
        showLeft();
        showRight();
        initListener();

    }


    private void initView() {
        View view = findViewById(R.id.titleBar);
        toolbarLeft = (ImageView) view.findViewById(R.id.toolbar_leftLin);
        toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
        toolbarTitle.setText("营业中心信息");

        tabBusiness = (TextView) findViewById(R.id.tab_business);
        tabPurchase = (TextView) findViewById(R.id.tab_purchase);
        View view2 = findViewById(R.id.header_select_date);
        etStartTime = (EditText) view2.findViewById(R.id.et_start_time);
        etEndTime = (EditText) view2.findViewById(R.id.et_end_time);
        etStartTime.setText(TimeUtil.getToday());
        etEndTime.setText(TimeUtil.getToday());
    }

    private void initListener() {
        toolbarLeft.setOnClickListener(this);
        tabBusiness.setOnClickListener(this);
        tabPurchase.setOnClickListener(this);
        toolbarTitle.setOnClickListener(this);
        goodReportCateListFragment.setOnDataTransmissionListener(new GoodReportCateListFragment.OnDataTransmissionListener() {
            @Override
            public void dataTransmission(boolean isPurchase,CateListBean cateListBean) {
                goodReportDishListFragment.setData(isPurchase,cateListBean);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toolbar_leftLin:
                finish();
                break;
            case R.id.tab_business:
                isPurchase = false;
                toolbarTitle.setText("营业中心信息");
                tabBusiness.setBackground(getResources().getDrawable(R.drawable.tab_bg_blue));
                tabPurchase.setBackgroundColor(getResources().getColor(R.color.white));

                break;
            case R.id.tab_purchase:
                isPurchase = true;
                toolbarTitle.setText("采购中心信息");
                tabPurchase.setBackground(getResources().getDrawable(R.drawable.tab_bg_blue));
                tabBusiness.setBackgroundColor(getResources().getColor(R.color.white));
                break;
            case R.id.toolbar_title:
                startActivity(new Intent(this, IndexActivity.class));
                break;
        }
    }

    public void showLeft() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        if (goodReportCateListFragment == null) {
            goodReportCateListFragment = new GoodReportCateListFragment();
            transaction.add(R.id.left_frag, goodReportCateListFragment);
        } else {
            transaction.show(goodReportCateListFragment);
        }
        transaction.commit();
    }

    public void showRight() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        if (goodReportDishListFragment == null) {
            goodReportDishListFragment = new GoodReportDishListFragment();
            transaction.add(R.id.right_frag, goodReportDishListFragment);
        } else {
            transaction.show(goodReportDishListFragment);
        }
        transaction.commit();
    }


}
